﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Text.RegularExpressions;
namespace Abhiruchi_Phase1
{
    /// <summary>
    /// Interaction logic for HRM_EmpCommunication.xaml
    /// </summary>
    public partial class HRM_EmpCommunication : Window
    {
        private static string formType; 
        private static string etype;
        private static string eid;


        public static bool varforSave = false;

        //private string etype = "CE";
        //private string eid = "CE000001";
        public static List<TestCase> tstCaseObj = new List<TestCase>();
        public static List<TestCase> tstCaseSaveObj = new List<TestCase>();

        public HRM_EmpCommunication()
        {
            InitializeComponent();
        }

        private void GetDataFromDB()
        {
            //This is DB Retrieval method
            if (formType == "EDIT")
            {
                DataTable mydt = CommunicationDAL.LoadCommDataFromDB(eid, 3);
                if (mydt.Rows.Count > 0)
                {
                    lblIdRes.Content = eid;
                    txtPeAdHouse.Text = mydt.Rows[0][1].ToString();
                    txtPeAdStreet.Text = mydt.Rows[0][2].ToString();
                    txtPeAdCity.Text = mydt.Rows[0][3].ToString();
                    cmbPeAdDistrict.Text = mydt.Rows[0][4].ToString();
                    cmbPeAdState.Text = mydt.Rows[0][5].ToString();
                    cmbPeAdPIN.Text = mydt.Rows[0][6].ToString();

                    txtPrAdHouse.Text = mydt.Rows[0][7].ToString();
                    txtPrAdStreet.Text = mydt.Rows[0][8].ToString();
                    txtPrAdCity.Text = mydt.Rows[0][9].ToString();
                    cmbPrAdDistrict.Text = mydt.Rows[0][10].ToString();
                    cmbPrAdState.Text = mydt.Rows[0][11].ToString();
                    cmbPrAdPIN.Text = mydt.Rows[0][12].ToString();

                    txtMobileHome.Text = mydt.Rows[0][13].ToString();
                    txtMobileWork.Text = mydt.Rows[0][14].ToString();
                    txtLandLineHome.Text = mydt.Rows[0][15].ToString();
                    txtLandLineWork.Text = mydt.Rows[0][16].ToString();
                    txtFCN.Text = mydt.Rows[0][17].ToString();
                    cmbRelationWithFCN.Text = mydt.Rows[0][18].ToString();
                    txtRelName.Text = mydt.Rows[0][19].ToString();
                    txtPersonalEmail.Text = mydt.Rows[0][20].ToString();
                    txtOfficialEmail.Text = mydt.Rows[0][21].ToString();
                }
            }
        }
        public void ShowNeworEditWindow()
        {
            if (etype == "PE")
            {
                lblIdRes.Content = eid;
                if (formType == "EDIT")
                {
                    GetDataFromDB();
                }
            }
            else if (etype == "CE")
            {
                lblIdRes.Content = eid;
                lblMobileWork.Visibility = Visibility.Collapsed;
                txtMobileWork.Visibility = Visibility.Collapsed;
                lblPersonalEmail.Visibility = Visibility.Collapsed;
                txtPersonalEmail.Visibility = Visibility.Collapsed;
                lblOfficialEmail.Visibility = Visibility.Collapsed;
                txtOfficialEmail.Visibility = Visibility.Collapsed;
                if (formType == "EDIT")
                {
                    GetDataFromDB();
                }
            }
        }

        private void chkSameAsPermanentAddress_Checked(object sender, RoutedEventArgs e)
        {
            if (chkSameAsPermanentAddress.IsChecked == true)
            {
                txtPrAdStreet.Text = txtPeAdStreet.Text;
                txtPrAdCity.Text = txtPeAdCity.Text;
                txtPrAdHouse.Text = txtPeAdHouse.Text;
                cmbPrAdDistrict.SelectedIndex = cmbPeAdDistrict.SelectedIndex;
                cmbPrAdState.SelectedIndex = cmbPeAdState.SelectedIndex;
                cmbPrAdPIN.SelectedIndex = cmbPeAdPIN.SelectedIndex;
            }
            else
            {
                txtPrAdStreet.Clear();
                txtPrAdCity.Clear();
                txtPrAdHouse.Clear();
                cmbPrAdDistrict.SelectedIndex = 0;
                cmbPrAdState.SelectedIndex = 0;
                cmbPrAdPIN.SelectedIndex = 0;
            }
        }


        #region Validation Testing
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (ValidationTesting())
            {

                DataTable mydtIdentity = CommunicationDAL.LoadCommDataFromDB(eid, 3);
                if (formType == "NEW" && varforSave == false)
                {
                    CommunicationDAL.CreateCommunication(eid, txtPeAdHouse.Text, txtPeAdStreet.Text, txtPeAdCity.Text, cmbPeAdState.SelectionBoxItem.ToString(), cmbPeAdPIN.SelectionBoxItem.ToString(), cmbPeAdDistrict.SelectionBoxItem.ToString(), txtPrAdHouse.Text, txtPeAdStreet.Text, txtPrAdCity.Text, cmbPrAdState.SelectionBoxItem.ToString(), cmbPrAdPIN.SelectionBoxItem.ToString(), cmbPrAdDistrict.SelectionBoxItem.ToString(), txtMobileHome.Text, txtMobileWork.Text, txtLandLineHome.Text, txtLandLineWork.Text, txtFCN.Text, cmbRelationWithFCN.SelectionBoxItem.ToString(), txtRelName.Text.ToString(), txtPersonalEmail.Text, txtOfficialEmail.Text, 1);

                    MessageBox.Show("Information Inserted Sucessfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                if (formType == "EDIT" && varforSave == false)
                {
                    CommunicationDAL.UpdateCommData(eid, txtPeAdHouse.Text, txtPeAdStreet.Text, txtPeAdCity.Text, cmbPeAdState.Text, cmbPeAdPIN.Text, cmbPeAdDistrict.Text, txtPrAdHouse.Text, txtPrAdStreet.Text, txtPrAdCity.Text, cmbPrAdState.Text, cmbPrAdPIN.Text, cmbPrAdDistrict.Text, txtMobileHome.Text, txtMobileWork.Text, txtLandLineHome.Text, txtLandLineWork.Text, txtFCN.Text, cmbRelationWithFCN.Text, txtRelName.Text.ToString(), txtPersonalEmail.Text, txtOfficialEmail.Text, 2);
                    MessageBox.Show("Information Updated Sucessfully", "Confirmation", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                varforSave = true;

            }


        }

        public bool ValidationTesting()
        {
            if (txtPeAdHouse.Text == "")
            {
                MessageBox.Show("Permanent Address House/Flat Field is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtPeAdHouse.Focus();
                return false;
            }
            if (txtPeAdStreet.Text == "")
            {
                MessageBox.Show("Permanent Address Street Field is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtPeAdStreet.Focus();
                return false;
            }

            if (txtPeAdCity.Text == "")
            {
                MessageBox.Show("Permanent Address City/Town/Village Field is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtPeAdCity.Focus();
                return false;
            }

            if (cmbPeAdDistrict.SelectedIndex == 0)
            {
                MessageBox.Show("Permanent Address District Selection is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbPeAdDistrict.Focus();
                return false;
            }
            if (cmbPeAdState.SelectedIndex == 0)
            {
                MessageBox.Show("Permanent Address State Selection is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbPeAdState.Focus();
                return false;
            }
            if (cmbPeAdPIN.SelectedIndex == 0)
            {
                MessageBox.Show("Permanent Address PIN Code Selection is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbPeAdPIN.Focus();
                return false;
            }
            if (txtPrAdHouse.Text == "")
            {
                MessageBox.Show("Present Address House/Flat Field is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtPrAdHouse.Focus();
                return false;
            }
            if (txtPrAdStreet.Text == "")
            {
                MessageBox.Show("Present Address Street Field is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtPrAdStreet.Focus();
                return false;
            }

            if (txtPrAdCity.Text == "")
            {
                MessageBox.Show("Present Address City/Town/Village Field is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtPrAdCity.Focus();
                return false;
            }

            if (cmbPrAdDistrict.SelectedIndex == 0)
            {
                MessageBox.Show("Present Address District Selection is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbPrAdDistrict.Focus();
                return false;
            }
            if (cmbPrAdState.SelectedIndex == 0)
            {
                MessageBox.Show("Present Address State Selection is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbPrAdState.Focus();
                return false;
            }
            if (cmbPrAdPIN.SelectedIndex == 0)
            {
                MessageBox.Show("Present Address PIN Code Selection is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbPrAdPIN.Focus();
                return false;
            }
            if (txtMobileHome.Text.Length > 10)
            {
                MessageBox.Show(" Please check the length of MobileHomeNo should not exceed 10 characters", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtMobileHome.Focus();
                return false;
            }
            else if (txtMobileHome.Text != "")
            {
                if (!Regex.Match(txtMobileHome.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
                {
                    MessageBox.Show(" Please Enter Correct Phone Number", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtMobileHome.Clear();
                    txtMobileHome.Focus();
                    return false;
                }
            }
            if (etype == "PE")
            {
                if (txtMobileWork.Text != "" && txtMobileWork.Text.Length > 10)
                {
                    MessageBox.Show(" Please check the length of MobileWorkNo should not exceed 10 characters", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtMobileWork.Focus();
                    return false;
                }
                if (txtMobileWork.Text != "")
                {
                    if (!Regex.Match(txtMobileWork.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
                    {
                        MessageBox.Show(" Please Enter Correct Phone Number", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        txtMobileWork.Clear();
                        txtMobileWork.Focus();
                        return false;
                    }
                }
            }
            if (txtLandLineHome.Text == "" && txtMobileHome.Text == "")
            {
                MessageBox.Show("LandLineHomeNo or MobileHomeNo is required ", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtLandLineHome.Focus();
                return false;
            }
            if (txtLandLineHome.Text.Length > 16)
            {
                MessageBox.Show("Please check the length of LandLineHomeNo should not Exceed 16 Numbers", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtLandLineHome.Focus();
                return false;
            }
            if (txtLandLineHome.Text != "")
            {
                if (!Regex.Match(txtLandLineHome.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
                {
                    MessageBox.Show(" Please Enter Correct Phone Number", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtLandLineHome.Clear();
                    txtLandLineHome.Focus();
                    return false;
                }
            }
            if (txtLandLineWork.Text.Length > 16)
            {
                MessageBox.Show("Please check the length of LandLineWorkNo should not exceed 16 Numbers", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtLandLineWork.Focus();
                return false;
            }
            if (txtLandLineWork.Text != "")
            {
                if (!Regex.Match(txtLandLineWork.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
                {
                    MessageBox.Show(" Please Enter Correct Phone Number", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtLandLineWork.Clear();
                    txtLandLineWork.Focus();
                    return false;
                }
            }
            if (txtFCN.Text == "")
            {
                MessageBox.Show("First ContactNo is Mandatory", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtFCN.Focus();
                return false;
            }
            if (!Regex.Match(txtFCN.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
            {
                MessageBox.Show(" Please Enter Correct Phone Number", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtFCN.Clear();
                txtFCN.Focus();
                return false;
            }
            if (txtFCN.Text.Length > 16)
            {
                MessageBox.Show("Please check the length of FirstContactNo should not exceed 16 characters", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtFCN.Focus();
                return false;
            }
            if (cmbRelationWithFCN.SelectedIndex == 0)
            {
                MessageBox.Show("Relation With First Contact is Mandatory", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                cmbRelationWithFCN.Focus();
                return false;
            }
            if (txtRelName.Text == "")
            {
                MessageBox.Show("First Contact Relation Name is Mandatory", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                txtRelName.Focus();
                return false;
            }
            if (txtRelName.Text != "")
            {
                Regex rx = new Regex(@"^[a-zA-Z\s.]*$");
                if (!rx.IsMatch(txtRelName.Text))
                {
                    MessageBox.Show("Enter Correct Relation Name", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtRelName.Focus();
                    return (false);
                }
            }
            if (etype == "PE")
            {
                if (txtPersonalEmail.Text == "")
                {
                    MessageBox.Show("Personal Email Id is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtPersonalEmail.Focus();
                    return (false);
                }
                if (txtPersonalEmail.Text != "")
                {
                    string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                          @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                          @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                    Regex re = new Regex(strRegex);
                    if (!re.IsMatch(txtPersonalEmail.Text))
                    {
                        MessageBox.Show("Enter Correct Email Id", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        txtPersonalEmail.Clear();
                        txtPersonalEmail.Focus();
                        return (false);
                    }
                }
                if (txtOfficialEmail.Text == "")
                {
                    MessageBox.Show("Official Email Id is Required", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    txtOfficialEmail.Focus();
                    return (false);
                }
                if (txtOfficialEmail.Text != "")
                {
                    string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                          @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                          @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                    Regex re = new Regex(strRegex);
                    if (!re.IsMatch(txtOfficialEmail.Text))
                    {
                        MessageBox.Show("Enter Correct Email Id", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        txtOfficialEmail.Clear();
                        txtOfficialEmail.Focus();
                        return (false);
                    }
                }
            }
            return true;
        }
        #endregion

        #region Validating Test Case - Manual
        private void btnAtTest_Click(object sender, RoutedEventArgs e)
        {
            tstCaseObj.Clear();
            Validate();
            foreach (TestCase t in tstCaseObj)
            {
                tstCaseSaveObj.Add(t);
            }
            string TestCaseLogSuccess = "";
            string TestCaseLogFail = "";
            foreach (TestCase t in tstCaseObj)
            {
                if (t.IsPass)
                {
                    TestCaseLogSuccess += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                else
                {
                    TestCaseLogFail += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }

            }
            MessageBox.Show("Test Case Pass - Log \n\n" + TestCaseLogSuccess + "\n\nTest Case Fail - Log\n\n" + TestCaseLogFail, "Test Case Log", MessageBoxButton.OK, MessageBoxImage.Information);

        }
        public void Validate()
        {
            int seed = 1;
            TestCase TestObj;
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "House No cannot be empty";
            if (txtPeAdHouse.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Street cannot be empty";
            if (txtPeAdStreet.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "City cannot be empty";
            if (txtPeAdCity.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }

            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Permanent Address District must be selected";
            if (cmbPeAdDistrict.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Permanent Address State Selection is Required";
            if (cmbPeAdState.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Permanent Address PIN Code Selection is Required";
            if (cmbPeAdPIN.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Present Address House/Flat Field is Required";
            if (txtPrAdHouse.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Present Address Street Field is Required";
            if (txtPrAdStreet.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Present Address City/Town/Village Field is Required";
            if (txtPrAdCity.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Present Address District Selection is Required";
            if (cmbPrAdDistrict.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Present Address State Selection is Required";
            if (cmbPrAdState.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Present Address PIN Code Selection is Required";
            if (cmbPrAdPIN.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please check the length of MobileHomeNo should not exceed 10 characters";
            if (txtMobileHome.Text != "" && txtMobileHome.Text.Length <= 10)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }

            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Mobile Home is Mandatory";
            if (txtMobileHome.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please Enter Correct Phone Number";
            if (Regex.Match(txtMobileHome.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            if (etype == "PE")
            {
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Please check the length of MobileWorkNo should not exceed 10 characters";
                if (txtMobileWork.Text != "" && txtMobileWork.Text.Length <= 10)
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Please Enter Correct Phone Number";
                if (txtMobileWork.Text != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "LandLineHomeNo or MobileHomeNo is required";
            if (txtLandLineHome.Text != "" && txtMobileHome.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please check the length of LandLineHomeNo should not Exceed 16 Numbers";
            if (txtLandLineHome.Text != "" && txtLandLineHome.Text.Length <= 16)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "LandlineHome Cannot Be Empty";
            if (txtLandLineHome.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please Enter Correct Phone Number";
            if (Regex.Match(txtLandLineHome.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please check the length of LandLineWorkNo should not exceed 16 Numbers";
            if (txtLandLineWork.Text != "" && txtLandLineWork.Text.Length <= 16)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "LandLine Work Cannot be Empty";
            if (txtLandLineWork.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please Enter Correct LandLine Phone Number";

            if (Regex.Match(txtLandLineWork.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "First ContactNo is Mandatory";
            if (txtFCN.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please Enter Correct FCN Phone Number";
            if (Regex.Match(txtFCN.Text.ToString(), @"^[-+]?[0-9]*\.?[0-9]+$").Success)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Please check the length of FirstContactNo should not exceed 16 characters";
            if (txtFCN.Text != "" && txtFCN.Text.Length <= 16)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "Relation With First Contact  is Mandatory";
            if (cmbRelationWithFCN.SelectedIndex != 0)
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            TestObj = new TestCase();
            TestObj.TestId = seed++;
            TestObj.TestCaseDesc = "First Contact Relation Name is Mandatory";
            if (txtRelName.Text != "")
            {
                TestObj.IsPass = true;
                tstCaseObj.Add(TestObj);
            }
            else
            {
                TestObj.IsPass = false;
                tstCaseObj.Add(TestObj);
            }
            if (etype == "PE")
            {
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Personal Email Id is Required";
                if (txtPersonalEmail.Text != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Enter Correct Email Id";
                string strRegexPe = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                       @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                       @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                Regex rePe = new Regex(strRegexPe);
                if (txtPersonalEmail.Text != "")
                {

                    if (rePe.IsMatch(txtPersonalEmail.Text))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Official Email ID is Mandatory";
                if (txtOfficialEmail.Text != "")
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Enter Correct Official Email Id";
                string strRegexOff = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                          @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                         @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
                Regex reOff = new Regex(strRegexOff);
                if (txtOfficialEmail.Text != "")
                {

                    if (reOff.IsMatch(txtOfficialEmail.Text))
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                }
            }

        }
        #endregion

        #region Validating DB Test Case - Manual
        private void btnDbTesting_Click(object sender, RoutedEventArgs e)
        {
            DataTable mydtIdentity = CommunicationDAL.LoadCommDataFromDB(eid, 3);
            if (mydtIdentity.Rows.Count == 0)
            {
                MessageBox.Show("Please Insert Record And Check The Data With DataBase", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            tstCaseObj.Clear();
            CheckDBDataWithForm(mydtIdentity);
            foreach (TestCase t in tstCaseObj)
            {
                tstCaseSaveObj.Add(t);
            }
            string TestCaseLogSuccess = "";
            string TestCaseLogFail = "";

            foreach (TestCase t in tstCaseObj)
            {
                if (t.IsPass)
                {
                    TestCaseLogSuccess += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                else
                {
                    TestCaseLogFail += "Test Case ID: " + t.TestId + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
            }

            MessageBox.Show("Test Case Pass - Log \n\n" + TestCaseLogSuccess + "\n\nTest Case Fail -Log\n\n" + TestCaseLogFail, "Test Case Log", MessageBoxButton.OK, MessageBoxImage.Information);

        }


        private bool CheckEntireDBDataWithForm(DataTable mydtIdentity)
        {
            if (lblIdRes.Content.ToString() != mydtIdentity.Rows[0][0].ToString() && txtPeAdHouse.Text != mydtIdentity.Rows[0][1].ToString() && txtPeAdStreet.Text != mydtIdentity.Rows[0][2].ToString() && txtPeAdCity.Text != mydtIdentity.Rows[0][3].ToString() && cmbPeAdState.Text != mydtIdentity.Rows[0][4].ToString() && cmbPeAdPIN.Text != mydtIdentity.Rows[0][5].ToString() && cmbPeAdDistrict.Text != mydtIdentity.Rows[0][6].ToString() && txtPrAdHouse.Text != mydtIdentity.Rows[0][7].ToString() && txtPrAdStreet.Text != mydtIdentity.Rows[0][8].ToString() && txtPrAdCity.Text != mydtIdentity.Rows[0][9].ToString() && cmbPrAdState.Text != mydtIdentity.Rows[0][10].ToString() && cmbPrAdPIN.Text != mydtIdentity.Rows[0][11].ToString() && cmbPrAdDistrict.Text != mydtIdentity.Rows[0][12].ToString() && txtMobileHome.Text != mydtIdentity.Rows[0][13].ToString() && txtMobileWork.Text != mydtIdentity.Rows[0][14].ToString() && txtLandLineHome.Text != mydtIdentity.Rows[0][15].ToString() && txtLandLineWork.Text != mydtIdentity.Rows[0][16].ToString() && txtFCN.Text != mydtIdentity.Rows[0][17].ToString() && cmbRelationWithFCN.Text != mydtIdentity.Rows[0][18].ToString() && txtRelName.Text != mydtIdentity.Rows[0][19].ToString() && txtPersonalEmail.Text != mydtIdentity.Rows[0][20].ToString() && txtOfficialEmail.Text != mydtIdentity.Rows[0][21].ToString())
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private void CheckDBDataWithForm(DataTable mydtIdentity)
        {

            TestCase TestObj;
            int seed = 1;
            if (mydtIdentity.Rows.Count > 0)
            {
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Employee ID should match";

                if (lblIdRes.Content.ToString() != mydtIdentity.Rows[0][0].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Permanent Employee House no. should Match";
                if (txtPeAdHouse.Text != mydtIdentity.Rows[0][1].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Permanent Employee StreetName should Match";
                if (txtPeAdStreet.Text != mydtIdentity.Rows[0][2].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Permanent Employee City should Match";
                if (txtPeAdCity.Text != mydtIdentity.Rows[0][3].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Permanent Employee District should Match";
                if (cmbPeAdDistrict.Text != mydtIdentity.Rows[0][4].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Permanent Employee State should Match";
                if (cmbPeAdState.Text != mydtIdentity.Rows[0][5].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Permanent Employee PIN should Match";
                if (cmbPeAdPIN.Text != mydtIdentity.Rows[0][6].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Present Employee House no. should Match";
                if (txtPrAdHouse.Text != mydtIdentity.Rows[0][7].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Present Employee Street name should Match";
                if (txtPrAdStreet.Text != mydtIdentity.Rows[0][8].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Present Employee City should Match";
                if (txtPrAdCity.Text != mydtIdentity.Rows[0][9].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Present Employee District should Match";
                if (cmbPrAdDistrict.Text != mydtIdentity.Rows[0][10].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Present Employee State should Match";
                if (cmbPrAdState.Text != mydtIdentity.Rows[0][11].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Present Employee PIN should Match";
                if (cmbPrAdPIN.Text != mydtIdentity.Rows[0][12].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }

                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Mobile Home should match";
                if (txtMobileHome.Text != mydtIdentity.Rows[0][13].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                if (etype == "PE")
                {
                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Mobile Work should match";

                    if (txtMobileWork.Text != mydtIdentity.Rows[0][14].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Landline Home should match";

                if (txtLandLineHome.Text != mydtIdentity.Rows[0][15].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Landline Work should match";
                if (txtLandLineWork.Text != mydtIdentity.Rows[0][16].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "FCN(First Contact No) should match";
                if (txtFCN.Text != mydtIdentity.Rows[0][17].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Relation With First Contact should match";
                if (cmbRelationWithFCN.Text != mydtIdentity.Rows[0][18].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                TestObj = new TestCase();
                TestObj.TestId = seed++;
                TestObj.TestCaseDesc = "Relation Name with First Contact should match";
                if (txtRelName.Text != mydtIdentity.Rows[0][19].ToString())
                {
                    TestObj.IsPass = false;
                    tstCaseObj.Add(TestObj);
                }
                else
                {
                    TestObj.IsPass = true;
                    tstCaseObj.Add(TestObj);
                }
                if (etype == "PE")
                {
                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Personal EmailID should match";
                    if (txtPersonalEmail.Text != mydtIdentity.Rows[0][20].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                    TestObj = new TestCase();
                    TestObj.TestId = seed++;
                    TestObj.TestCaseDesc = "Official EmailID should match";
                    if (txtOfficialEmail.Text != mydtIdentity.Rows[0][21].ToString())
                    {
                        TestObj.IsPass = false;
                        tstCaseObj.Add(TestObj);
                    }
                    else
                    {
                        TestObj.IsPass = true;
                        tstCaseObj.Add(TestObj);
                    }
                }
            }

        }
        #endregion




        private void btnNext_Click(object sender, RoutedEventArgs e)
        {
            if (varforSave == false)
            {
                btnSave_Click(this, e);
            }
        }

        private void btnPrevious_Click(object sender, RoutedEventArgs e)
        {
            if (varforSave == false)
            {
                btnSave_Click(this, e);
            }
        }

        private void btnTestPrev_Click(object sender, RoutedEventArgs e)
        {
            tstCaseSaveObj.Clear();
            tstCaseObj.Clear();
            Validate();
            foreach (TestCase t in tstCaseObj)
            {
                tstCaseSaveObj.Add(t);
            }

            DataTable mydtIdentity = CommunicationDAL.LoadCommDataFromDB(eid, 3);
            if (mydtIdentity.Rows.Count == 0)
            {
                MessageBox.Show("Please Insert Record And Check The Data With DataBase", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }
            else
            {
                tstCaseObj.Clear();
                CheckDBDataWithForm(mydtIdentity);
                foreach (TestCase t in tstCaseObj)
                {
                    tstCaseSaveObj.Add(t);
                }
            }
            string TestCaseLogSuccess = "";
            string TestCaseLogFail = "";
            int value = 1;
            foreach (TestCase t in tstCaseSaveObj)
            {
                
                if (t.IsPass)
                {                    
                    TestCaseLogSuccess += "Test Case ID: " + value + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                else
                {
                    TestCaseLogFail += "Test Case ID: " + value + ", Test Case: " + t.TestCaseDesc + ", Is Pass: " + t.IsPass + "\n";
                }
                value++;
            }
            MessageBox.Show("Testy Case Pass - Log \n\n" + TestCaseLogSuccess + "\n\nTest Case Fail - Log\n\n" + TestCaseLogFail, "Test Case Log", MessageBoxButton.OK, MessageBoxImage.Information);
        }       
        private void btnTestNext_Click(object sender, RoutedEventArgs e)
        {
            btnTestPrev_Click(this, e);
        }
        private void btnTestSave_Click(object sender, RoutedEventArgs e)
        {
            btnTestPrev_Click(this, e);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            #region Temp Code
            if (rdoNEW.IsChecked == true)
            {
                formType = "NEW";
            }
            else
            {
                formType = "EDIT";
            }

            if (rdoPE.IsChecked == true)
            {
                etype = "PE";
            }
            else
            {
                etype = "CE";
            }

            eid = txtTempEID.Text;

            #endregion
            ShowNeworEditWindow();
            if (formType == "NEW")
            {
                txtPeAdHouse.Focus();
            }
        }
    }
    public class TestCase
    {
        public int TestId;
        public string TestCaseDesc;
        public bool IsPass;
    }
}
